package tan.dft.listviewlotrinh;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class LotrinhAdapter extends ArrayAdapter<Lotrinh> {
	private ArrayList<Lotrinh> array;
	private Context mContext;

	public LotrinhAdapter(Context context, int textViewResourceId,
			ArrayList<Lotrinh> objects) {
		super(context, textViewResourceId, objects);
		this.mContext = context;
		this.array = objects;
	}

	// phuong thuc goi de lay tung phan tu cua mang xay dung tung item cua
	// listview
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// mang co bao nhieu phan tu se co bay nhieu item cua listview
		// buoc1: lay layout ma tao ra item (layout thu position)
		View lotrinhtView = convertView;
		if (lotrinhtView == null) {
			lotrinhtView = new LotrinhLayoutItem(mContext);
		}

		Lotrinh arraylotrinh = array.get(position);

		// buoc3: lay tung thanh phan cau tao len item
		TextView lotrinhidmayql = ((LotrinhLayoutItem) lotrinhtView).lotrinhidmayql;
		TextView litrinhidmay = ((LotrinhLayoutItem) lotrinhtView).lotrinhidmay;
		TextView lotrinhdate = ((LotrinhLayoutItem) lotrinhtView).lotrinhdate;
		TextView lotrinhlat = ((LotrinhLayoutItem) lotrinhtView).lotrinhlat;
		TextView lotrinhlng = ((LotrinhLayoutItem) lotrinhtView).lotrinhlng;
		TextView lotrinhthoigian = ((LotrinhLayoutItem) lotrinhtView).lotrinhthoigian;

		lotrinhidmayql.setText("" + arraylotrinh.getIdmayql());
		litrinhidmay.setText("" + arraylotrinh.getIdmay());
		lotrinhdate.setText("" + arraylotrinh.getDate());
		lotrinhlat.setText("" + arraylotrinh.getLat());
		lotrinhlng.setText("" + arraylotrinh.getLng());
		lotrinhthoigian.setText("" + arraylotrinh.getThoigian());

		return lotrinhtView;
	}

}
